// Fill out your copyright notice in the Description page of Project Settings.


#include "AI/TUAICharacter.h"
#include "AI/TUAIController.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Component/TUWeaponComponent.h"
#include "Component/TUAIWeaponComponent.h"
#include "BrainComponent.h"



ATUAICharacter::ATUAICharacter(const FObjectInitializer& ObjInit)
: Super(ObjInit.SetDefaultSubobjectClass<UTUAIWeaponComponent>("WeaponComponent"))
{
    AutoPossessAI = EAutoPossessAI::Disabled;
    AIControllerClass = ATUAIController::StaticClass();

    bUseControllerRotationYaw = false;
    if (GetCharacterMovement())
    {
        GetCharacterMovement()->bUseControllerDesiredRotation = true;
        GetCharacterMovement()->RotationRate = FRotator(0.0f, 200.0f, 0.0f);
    }

     /*HealthWidgetComponent = CreateDefaultSubobject<UWidgetComponent>("HealthWidgetComponent");
    HealthWidgetComponent->SetupAttachment(GetRootComponent());
    HealthWidgetComponent->SetWidgetSpace(EWidgetSpace::Screen);
    HealthWidgetComponent->SetDrawAtDesiredSize(true);*/
}

void ATUAICharacter::OnDeath()
{
    Super::OnDeath();

    const auto TUController = Cast<AAIController>(Controller);
    if (TUController && TUController->BrainComponent)
    {
        TUController->BrainComponent->Cleanup();
    }
}
